//重写数组的部分方法




let oldArrayProto = Array.prototype; // 获取数组的原型


export let newArrayProto = Object.create(oldArrayProto);

let methods = ['push','pop','shift','unshift','reverse','sort','splice']


methods.forEach(method=>{
  newArrayProto[method] = function(...args){
    const result = oldArrayProto[method].call(this,...args) // 内部调用原来的方法 函数劫持 切片编程

    // 需要对新增的对象进行再次劫持

    let inserted;
    switch(method){
      case 'push':
        case'unshift':
        inserted = args;
        break
      case 'splice':
        inserted = args.slice(2)
      default:
        break
    }
    if(inserted){
      let ob = this.__ob__.observeArray(inserted)
    }
    return result
    
  }
})